//=============================================================================
// FireChuckerAltFire - Fires a fireball. Borrowed heavily from BioChargedFire.
//=============================================================================
class FireChuckerAltFire extends TFProjectileFire;

var() float GoopUpRate;
var() int MaxGoopLoad;
var() int GoopLoad;
var() Sound HoldSound;
var() class<Projectile> ProjectileClassBlue;
var() sound HoldAmbientSound;

var int AmmoPerCharge;

function float MaxRange()
{
	//Range depends on charge: More charge => less range.
	return 10000 / (0.5 + (GoopLoad / 2));
}

function ModeHoldFire()
{
	if(Weapon.AmmoAmount(ThisModeNum) > 0)
	{
		Super.ModeHoldFire();
		GotoState('Hold');
	}
}

state Hold
{
	simulated function BeginState()
	{
		GoopLoad = 0;
		SetTimer(GoopUpRate, true);
		Weapon.PlayOwnedSound(HoldSound, SLOT_Interact, TransientSoundVolume);
		Weapon.LoopAnim(FireLoopAnim, FireLoopAnimRate, TweenTime);
		Instigator.AmbientSound = HoldAmbientSound;
		Timer();
	}

	simulated function Timer()
	{
		local int i;

		if(Weapon.AmmoAmount(ThisModeNum) > 0)
			GoopLoad++;

		for(i=0; i<AmmoPerCharge; i++)
			Weapon.ConsumeAmmo(ThisModeNum, 1);

		if (GoopLoad == MaxGoopLoad || Weapon.AmmoAmount(ThisModeNum) == 0)
		{
			SetTimer(0.0, false);
			GotoState('');
		}
	}
}

function projectile SpawnProjectile(Vector Start, Rotator Dir)
{
	local Projectile FireBall;

	Instigator.AmbientSound = None;
	GotoState('');

	if(GoopLoad == 0)
		return None;

	Start += vector(Dir) * GoopLoad * 8;
	FireBall = Spawn(ProjectileClass,,, Start, Dir);

	if(FireBall != None)
		FireBallProj(FireBall).Scaling = GoopLoad;

	GoopLoad = 0;

	if(Weapon.AmmoAmount(ThisModeNum) <= 0)
		Weapon.OutOfAmmo();

	return FireBall;
}

function StartBerserk()
{
	GoopUpRate = default.GoopUpRate*0.75;
}

function StopBerserk()
{
	GoopUpRate = default.GoopUpRate;
}

//FireSound volume depends on how big the fireball will be.
event ModeDoFire()
{
	ShakeOffsetMag.X += GoopLoad * 2;
	ShakeOffsetMag.Y += GoopLoad;
	ShakeOffsetMag.Z += GoopLoad;
	ShakeOffsetTime += GoopLoad / 3;

	TransientSoundVolume *= 0.3 + GoopLoad / 5;
	Super.ModeDoFire();
	TransientSoundVolume = Default.TransientSoundVolume;

	ShakeOffsetMag = Default.ShakeOffsetMag;
	ShakeOffsetTime = Default.ShakeOffsetTime;
}

defaultproperties
{
     GoopUpRate=0.250000
     MaxGoopLoad=10
     HoldSound=SoundGroup'WeaponSounds.BioRifle.BioRiflePowerUp'
     ProjectileClassBlue=Class'taskforces.FireBallProjBlue'
     HoldAmbientSound=Sound'TFMedia.FireChucker.FireChuckerAltLoop'
     AmmoPerCharge=4
     ProjSpawnOffset=(X=20.000000,Y=8.000000,Z=-16.000000)
     bSplashDamage=True
     bRecommendSplashDamage=True
     bFireOnRelease=True
     FireAnim="AltFire"
     FireLoopAnim="AltFireLoop"
     FireEndAnim=
     FireLoopAnimRate=3.000000
     FireSound=Sound'TFMedia.FireChucker.FireChuckerAltFireSound'
     FireForce="BioRifleFire"
     FireRate=0.300000
     AmmoClass=Class'taskforces.FireChuckerAmmo'
     ShakeRotTime=1.000000
     ShakeOffsetMag=(X=1.000000,Y=1.000000,Z=1.000000)
     ShakeOffsetRate=(X=-100.000000,Y=200.000000,Z=200.000000)
     ShakeOffsetTime=1.000000
     ProjectileClass=Class'taskforces.FireBallProj'
     BotRefireRate=0.500000
     WarnTargetPct=0.700000
}
